
// 入口
module.exports = function (app) {
  const config = require('../config/config.js');

  const db = require('../db/index.js');


  // 在子路钱引入验证，无法通过验证则无法通过子路由
  // 引入token验证
  const authhs256 = require('../middlewares/authhs256/authentication');

  // 导入数据库
  db.connect(config.myconnect);
  // 建立连接
  const conmesage = db.connection;

  conmesage.on('error', (error) => {  // 数据库连接失败

    app.use((req, res, next) => {
      return res.json({
        code: 203,
        mes: '请检查网络连通性'
      });
    });
  });
  conmesage.once('open', (callback) => {


    // app.use('/auditing', authhs256.ensureAuthenticated, require('./auditing'));
    app.use('/user', authhs256.ensureAuthenticated, require('./users'));//暂无
    app.use('/patient', authhs256.ensureAuthenticated, require('./patient'));//患者信息管理,分诊操作
    app.use('/source', authhs256.ensureAuthenticated, require('./Sources'));//患者来源管理模块
    app.use('/department', authhs256.ensureAuthenticated, require('./departments'));//科室模块
    app.use('/grade', authhs256.ensureAuthenticated, require('./grades'));//会员模块
    app.use('/role', authhs256.ensureAuthenticated, require('./roles'));//权限模块
    app.use('/cmmuseum', authhs256.ensureAuthenticated, require('./Cmmuseums'));//门店模块
    app.use('/doctor', authhs256.ensureAuthenticated, require('./doctors'));//人员操作路由,排班设置,登录
    app.use('/registration', authhs256.ensureAuthenticated, require('./registrations'));//挂号费模块
    app.use('/sheduling', authhs256.ensureAuthenticated, require('./shedulings'));//排班模块
    app.use('/order', authhs256.ensureAuthenticated, require('./order'));//订单模块
    app.use('/casetemplate', authhs256.ensureAuthenticated, require('./casetemplate'));//病例模板
    app.use("/operationLog", require('./OperationLog'));//日志模块
    // app.use("/outpatientService", require('./outpatientService'));//门诊
    // app.use('/prescription', require('./prescription'));//处方
    // app.use('/surgicalTreatment', require('./surgicalTreatment'));//外科治疗
    // app.use('/refund', require('./refund.js'));//退费模块
    app.use('/home', authhs256.ensureAuthenticated, require('./home.js'));//首页工作台
    app.use('/registrationinfor', authhs256.ensureAuthenticated, require('./registrationinfor.js'));//挂号信息表
    app.use("/outpatientService", authhs256.ensureAuthenticated, require('./outpatientService'));//门诊
    app.use('/prescription', authhs256.ensureAuthenticated, require('./prescription'));//处方
    app.use('/surgicalTreatment', authhs256.ensureAuthenticated, require('./surgicalTreatment'));//外科治疗
    app.use('/refund', authhs256.ensureAuthenticated, require('./refund.js'));//退费模块
    app.use('/login', require('./login'));//人员操作路由,排班设置,登录
    app.use('/cmmuseumlist', require('./Cmmuseums'));//获取门店列表
    // catch 404 and forward to error handler
    app.use((req, res, next) => {
      const err = new Error('Not Found');
      err.status = 404;
      next(err);
    });

    // error handler
    app.use((err, req, res, next) => {
      // set locals, only providing error in development
      res.locals.message = err.message;
      res.locals.error = req.app.get('env') === 'development' ? err : {};

      // render the error page
      res.status(err.status || 500);
      res.render('error');
    });
  });
};
